package edu.duixiang;

public class caer {

    public static void main(String[] args) {
        car car;
        car=new car();
        double s=10;
        car.sup();
        car=new bus();//向上转型，公交车是车
        car.sup();

        //car car1=new bus();
        /*向下转型，防止出现异常，需要进行一个判断
        * if(!(car instanceof bus)||bus==null)
        * return false */
        //bus bus1=(bus) new car();//向下转型，就相当于转了个弯，防止出现异常
        System.out.println(car.s);
    }
}
class car{
    public int s;

    void sup(){
        double s=0;
        s+=10;
    }
}
class bus extends car{
    @Override
    void sup() { s+=5; }
}
